﻿package bdz.projects.lavender.doi.ui
{
	import bdz.common.model.AppEnvironment;
	import bdz.common.display.DisplayLoader;
	import bdz.common.events.GenericEvent;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.*;
	import flash.external.ExternalInterface;
	
	import gs.*;
	import gs.easing.*;
	import flash.net.*;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.*;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	/**
	 * ...
	 * @author ...
	 */
	public class DOIModulePlaneView extends DOIPlane 
	{
		
		private var _padding:Number = 2;
		
		
		private var contentLayer:MovieClip;
		
		private var _moduleTitle:Plane;
		private var _currentTopic:Number = 0;
		private var _topicRoller:Plane;
		private var _topicHolder:DisplayObject3D;
		private var _topicCloser:Plane;
		private var _lastSelected:PaperMenuItem;
		
		private var _modTop:MovieClip;
		private var _mtopmat:MovieMaterial;
		private var _topicLabel:Plane;
		
		private var _currentaudio:String;
		private var _currentmovie:String;
		
		public var planeView:DOIPlanesView;
		
		private var _nextClicker:Plane;
		private var _nextMC:MovieClip;
		private var _nextMat:MovieMaterial;
		private var _homeClicker:Plane;
		private var _homeMC:MovieClip;
		private var _homeMat:MovieMaterial;
		private var _env:AppEnvironment;
		private var _nextOnQueue:Object;
		private var _labelmc:MovieClip;
		private var _mlabelmat:MovieMaterial;
		
		private var _modStepByStep:Plane;
		private var _modsbsmat:MovieMaterial;
		private var _modsbsmc:MovieClip;
		
		private var _modPlayer:Plane;
		private var _modPlayerMat:MovieMaterial;
		private var _modPlayerMC:MovieClip;
		private var _modPauser:Plane;
		private var _modPauserMat:MovieMaterial;
		private var _modPauserMC:MovieClip;
		
		private var _modPauserHolder:DisplayObject3D;
		
		private var _toprollMC:MovieClip;
		private var _topcloseMC:MovieClip;
		
		private var _endoftheworld:Boolean = false;
		public function DOIModulePlaneView(catname:String, dobj:Object, defstep:Number = 0) {
			super(catname, null);
			_defobj = dobj;
			_currentTopic = defstep;
			
		}
		private function createPauserPlane():void {
			
			_modPauserHolder = new DisplayObject3D("_modPauserHolder");
			
			_modPauserHolder.z = -30;
			_modPauserHolder.y = -185;
			
			_modPauserHolder.x = 400;
			
			
			_modPauserMC = new ModTopicPauser();
			_modPauserMat = new MovieMaterial(_modPauserMC, true, false);
			_modPauserMat.smooth = _modPauserMat.interactive = true;
			_modPauserMC.defmat = _modPauserMat;
			
			_modPauser = new Plane(_modPauserMat, _modPauserMC.width, _modPauserMC.height, 4, 4);
			_modPauser.z = -10;
			_modPauser.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onPlayPauseMenuClick);
			_modPauser.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onPlayPauseMenuRoll);
			_modPauser.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onPlayPauseMenuRoll);
			
			_matref.push(_modPauserMat);
			_mcref.push(_modPauserMC);
			
			_modPauserHolder.addChild(_modPauser, "_modPauser");
			
			
			
			_modPlayerMC = new ModTopicPlayer();
			_modPlayerMat = new MovieMaterial(_modPlayerMC, true, false);
			_modPlayerMat.smooth = _modPlayerMat.interactive = true;
			_modPlayerMC.defmat = _modPlayerMat;
			_modPlayer = new Plane(_modPlayerMat, _modPlayerMC.width, _modPlayerMC.height, 4, 4);
			_modPlayer.z = 10;
			_modPlayer.rotationZ = _modPlayer.rotationY = 180;
			
			_matref.push(_modPlayerMat);
			_mcref.push(_modPlayerMC);
			
			_modPlayer.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onPlayPauseMenuClick);
			_modPlayer.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onPlayPauseMenuRoll);
			_modPlayer.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onPlayPauseMenuRoll);
			_modPauserHolder.addChild(_modPlayer, "_modPlayer");
			
			_frontContainer.addChild(_modPauserHolder, "_modPauserHolder");
			
			_planeRef.push( { face:_frontContainer, plane:_modPauserHolder } );
			
		}
		private function destroyPauserPlane():void {
			try{
				_modPlayerMat.destroy();
				_modPauserMat.destroy();
				
				_modPauserHolder.removeChild(_modPlayer);
				_modPauserHolder.removeChild(_modPauser);
				_frontContainer.removeChild(_modPauserHolder);
			}catch (e:Error) {
				
			}
		}
		
		private function onPlayPauseMenuClick(evt:InteractiveScene3DEvent):void {
			if (evt.target == _modPauser) {
				_modPlayerMC.roll.visible = false;
				_modPlayerMC.defmat.drawBitmap();
				try{
					contentLayer.animationPause();
				}catch(e:Error){
					
				}
				TweenMax.to(_modPauserHolder, .8, { rotationX:180, ease:Strong.easeInOut } );
			}else {
				try{
					contentLayer.animationResume();
				}catch(e:Error){
					
				}
				_modPauserMC.roll.visible = false;
				_modPauserMC.defmat.drawBitmap();
				revertTopicButton();
				pmenu.hideAll();
				deactivateControls();
				viewport.buttonMode = viewport.useHandCursor = false;
				TweenMax.to(_modPauserHolder, .8, { rotationX:0, ease:Strong.easeInOut } );
			}
		}
		private function onPlayPauseMenuRoll(evt:InteractiveScene3DEvent):void {
			if (evt.target == _modPauser) {
				_modPauserMC.roll.visible = (evt.type == InteractiveScene3DEvent.OBJECT_OVER);
				_modPauserMC.defmat.drawBitmap();
			}else {
				_modPlayerMC.roll.visible = (evt.type == InteractiveScene3DEvent.OBJECT_OVER);
				_modPlayerMC.defmat.drawBitmap();
			}
			super.roll3DActions(evt);
		}
		
		private function onContentStartLoad(evt:GenericEvent):void {
			destroyPauserPlane();
			planeView.createPreloader(new Preloader(), -20, false);
		}
		private function onContentLoadProgress(evt:GenericEvent):void {
			planeView.setPreloaderValue(evt.data);
		}
		private function onContentPreloadComplete(evt:GenericEvent):void {
			createPauserPlane();
			planeView.destroyPreloader();
			checkHasNext();	
		}
		override protected function renderPlane(delay:Number = 0):void {
			
			super.renderPlane(delay);
			_endoftheworld = false;
			_env = AppEnvironment.getEnv();
			for each(var dobj:Object in _defobj.steps) {
				dobj.baseRenderer = "CatNavItem";
				dobj.labelRenderer = "CatNavItemLabel";
			}
			var objr:* = getDefinitionByName(_renderer);
			contentLayer = new objr();
			
			contentLayer.addEventListener("StartPreloading", onContentStartLoad);
			contentLayer.addEventListener("PreloadProgress", onContentLoadProgress);
			contentLayer.addEventListener("PreloadingComplete", onContentPreloadComplete);
			contentLayer.addEventListener("PlayComplete", onContentPlayComplete);
			
			
			_mcref.push(contentLayer);
			
			
			var mat:MovieMaterial = new MovieMaterial(contentLayer, false , false, false);
			mat.animated = true;
			contentLayer.defmat = mat;
			//mat.smooth = true;
			
			_matref.push(mat);
			
			
			var pl:Plane = new Plane(mat, contentLayer.width, contentLayer.height, 1, 1);
			_frontContainer.addChild(pl, "front");
			
			_planeRef.push( { face:_frontContainer, plane:pl } );
			
			
				
			pmenu = new PaperMenu(_defobj.steps, "horizontal", -5, 10, 1, false);
			_frontContainer.addChild(pmenu);
			
			_planeRef.push( { face:_frontContainer, plane:pmenu } );
			
			pmenu.z = -60;
			pmenu.y = -60;
			
			
			
			createModuleElements();
			
			_lastSelected = pmenu.planes[_currentTopic];
			
			dispatchEvent(new GenericEvent("ContentChanged", contentObject.steps[pmenu.planes[_currentTopic].defaultInformation.index]));
			
			resolveResources();
			//visible = false;
		}
		private function setNextOnQueue():void {
			
		}
		private function checkHasNext():void {
			var appRef:DOIMain = _env.getSetting("application") as DOIMain;
			if (contentObject.steps[_currentTopic + 1]) {
				//next step available
				_nextOnQueue = contentObject.steps[_currentTopic + 1];
			}else if (contentObject.parent.modules[contentObject.index + 1]) {
				//next module available
				_nextOnQueue = contentObject.parent.modules[contentObject.index + 1];
			}else if (_env.getSetting("doiInfo")[contentObject.parent.index + 1]) {
				//next chapter
				_nextOnQueue = _env.getSetting("doiInfo")[contentObject.parent.index + 1];
			}else {
				//ended... back to start?
				_endoftheworld = true;
				
			}
		}
		
		private function addNextButton():void {
			_nextMC = new Nexter();
			_nextMat = new MovieMaterial(_nextMC, true, false, false);
			_nextMC.defmat = _nextMat;
			_nextMC.deflabel = _nextOnQueue.name;
			_nextMat.doubleSided = false;
			_nextMat.smooth = true;
			_nextMat.interactive = true;
			_nextClicker = new Plane(_nextMat, _nextMC.width, _nextMC.height, 5, 5);
			_nextClicker.z = -1000;
			_nextClicker.x = (contentLayer.width / 2) - 30;
			_nextClicker.y = 50;
			_nextClicker.rotationY = 270;
			
			_nextClicker.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onNextClick);
			_nextClicker.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onNextRoll);
			_nextClicker.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onNextRoll);
			
			
			
			
			
			_frontContainer.addChild(_nextClicker);
			_planeRef.push( { face:_frontContainer, plane:_nextClicker } );
			
			
			TweenMax.to(_nextClicker, 1, { z: -40, ease:Strong.easeInOut, rotationY:0 } );
			
			createHomer();
			
			
		}
		private function createHomer(b:Boolean = true):void {
			_homeMC = new Homer();
			_homeMat = new MovieMaterial(_homeMC, true, false, false);
			_homeMC.defmat = _homeMat;
			
			_homeMat.doubleSided = false;
			_homeMat.smooth = true;
			_homeMat.interactive = true;
			_homeClicker = new Plane(_homeMat, _homeMC.width, _homeMC.height, 5, 5);
			_homeClicker.z = -1000;
			_homeClicker.x = (contentLayer.width / 2) - 30;
			
			_homeClicker.y = b ? -50 : 0;
			_homeClicker.rotationY = 270;
			
			_homeClicker.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onHomeClick);
			_homeClicker.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onHomeRoll);
			_homeClicker.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onHomeRoll);
			
			_frontContainer.addChild(_homeClicker);
			_planeRef.push( { face:_frontContainer, plane:_homeClicker } );
			TweenMax.to(_homeClicker, 1, { delay:.3, z: -40, ease:Strong.easeInOut, rotationY:0 } );
			setTimeout(contentLayer.animationPause, 1500, false);
		}
		private function onHomeRoll(evt:InteractiveScene3DEvent):void {
			if (evt.type == InteractiveScene3DEvent.OBJECT_OVER) {
				_homeMC.showRoll();
			}else {
				_homeMC.hideRoll();
			}
			super.roll3DActions(evt);
		}
		private function onHomeClick(evt:InteractiveScene3DEvent):void {
			var appRef:DOIMain = _env.getSetting("application") as DOIMain;
			appRef.backToNav();
		}
		private function onNextRoll(evt:InteractiveScene3DEvent):void {
			if (evt.type == InteractiveScene3DEvent.OBJECT_OVER) {
				_nextMC.showRoll();
			}else {
				_nextMC.hideRoll();
			}
			super.roll3DActions(evt);
		}
		private function onNextClick(evt:InteractiveScene3DEvent):void {
			var appRef:DOIMain = _env.getSetting("application") as DOIMain;
			setTimeout(appRef.resolveActiveData, 400, _nextOnQueue, false);
			planeView.createPreloader(new Preloader(), -20, false);
			TweenMax.to(_nextClicker, 1, {ease:Strong.easeInOut, z:-1000, rotationY:-180, onComplete:_frontContainer.removeChild, onCompleteParams:[_nextClicker] } );
		}
		private function onContentPlayComplete(evt:GenericEvent):void {
			if (_endoftheworld) {
				createHomer(false);
				return;
			}
			if(_nextOnQueue.type == "category"){
				//var toremove:Plane = _nextClicker;
				//TweenMax.to(toremove, .4, { ease:Strong.easeInOut, z: -1000, rotationY: -180, onComplete:_frontContainer.removeChild, onCompleteParams:[toremove] } );
				contentLayer.dim();
				addNextButton();
			}else {
				var appRef:DOIMain = _env.getSetting("application") as DOIMain;
				setTimeout(appRef.resolveActiveData, 400, _nextOnQueue, false, true);
				planeView.createPreloader(new Preloader(), -20, false);
				
			}
		}
		override protected function dispatchCreated():void {
			super.dispatchCreated();
			playAnimation();
		}
		private function resolveResources():void {
			var def:XMLList = new XMLList(_defobj.steps[_currentTopic].definition);
			_currentaudio = def[1].mp3
			_currentmovie = _defobj.steps[_currentTopic].swfimage;
		}
		private function playAnimation():void {
			var def:XMLList = new XMLList(_defobj.steps[_currentTopic].definition);
			contentLayer.clean();
			
			contentLayer.applyNewResource(_currentaudio, _currentmovie, def[0].caption, _defobj.steps[_currentTopic].audiourl.split("|").join(" "));
		}
		
		private function createStepByStepClicker():void {
			try {
				_frontContainer.removeChild(_modStepByStep);
			}catch (e:Error) { }
			try{
				_modsbsmat.destroy();
			}catch (e:Error) { }
			if (_modsbsmc) {
				_modsbsmc = null;
			}
			_modsbsmc = new ModStepByStepLabel();
			_mcref.push(_modsbsmc);
			
			_modsbsmat = new MovieMaterial(_modsbsmc, true, false, false );
			_modsbsmat.smooth = true;
			_modsbsmat.interactive = true;
			_modsbsmc.defmat = _modsbsmat;
			_matref.push(_modsbsmat);
			
			_modStepByStep = new Plane(_modsbsmat, _modsbsmc.width, _modsbsmc.height, 3, 3);
			
			_modStepByStep.z = -1000;
			_modStepByStep.x = 360;
			_modStepByStep.y = 195;
			_modStepByStep.rotationY = -180;
			_modStepByStep.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onStepByStepLink);
			_modStepByStep.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onStepMenuRoll);
			_modStepByStep.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onStepMenuRoll);
			//_modStepByStep.scale = 0;
			_frontContainer.addChild(_modStepByStep, "modStepByStep");
			_planeRef.push( { face:_frontContainer, plane:_modStepByStep } );
			
			TweenMax.to(_modStepByStep, 1, { rotationY:0, z: -40, ease:Strong.easeInOut } );
			
		}
		private function onStepMenuRoll(evt:InteractiveScene3DEvent):void {
			if (evt.type == InteractiveScene3DEvent.OBJECT_OVER) {
				_modsbsmc.showHighlight();
			}else {
				_modsbsmc.hideHighlight();
			}
			super.roll3DActions(evt);
		}
		private function onStepByStepLink(evt:InteractiveScene3DEvent):void {
			var reply:Boolean = ExternalInterface.call("openWin", "Guide.aspx?i=" + contentObject.steps[_currentTopic].shortname);
			if (!reply) {
				navigateToURL(new URLRequest("../../Guide.aspx?i=" + contentObject.steps[_currentTopic].shortname), "_blank");
			}
			onTopicMenuClick();
		}
		private function createModLabel():void {
			try {
				_frontContainer.removeChild(_moduleTitle);
			}catch (e:Error){
				
			}
			try {
				_mlabelmat.destroy();
			}catch(e:Error){}
			if (_labelmc) {
				_labelmc = null;
			}
			_labelmc = new ModLabel(); //library items
			_labelmc.definfo = "<b>"+_defobj.name.split("|").join(" ") + ":   <font color='#9f0029'>"+_defobj.steps[_currentTopic].audiourl.split("|").join(" ")+"</font></b>";
			_mcref.push(_labelmc);
			
			_mlabelmat = new MovieMaterial(_labelmc, true, false, false);
			_mlabelmat.smooth = true;
			_labelmc.defmat = _mlabelmat;
			_matref.push(_mlabelmat);
			
			_moduleTitle = new Plane(_mlabelmat, _labelmc.width, _labelmc.height, 3, 3);
			_moduleTitle.z = -1000;
			_moduleTitle.x = 20;
			_moduleTitle.y = 195;
			_moduleTitle.rotationY = 180;
			_frontContainer.addChild(_moduleTitle, "modTitle");
			_planeRef.push( { face:_frontContainer, plane:_moduleTitle } );
			
			TweenMax.to(_moduleTitle, 1, { rotationY:0, z: -40, ease:Strong.easeInOut } );
		}
		
		
		private function createModuleElements():void {
			
			setTimeout(createModLabel, 1000);
			setTimeout(createStepByStepClicker, 1000);
			//createTopicLabel();
			//_planeRef.push( { face:_frontContainer, plane:_topicLabel } );
			
			_toprollMC = new ModTopicRoller();
			_mcref.push(_toprollMC);
			
			var rollmat:MovieMaterial = new MovieMaterial(_toprollMC, true, false, false);
			_toprollMC.defmat = rollmat;
			rollmat.smooth = true;
			rollmat.doubleSided = false;
			rollmat.interactive = true;
			_matref.push(rollmat);
			
			_topicHolder = new DisplayObject3D("topicHolder");
			_topicHolder.z = -30;
			_topicHolder.y = -185;
			
			_frontContainer.addChild(_topicHolder, "topicHolder");
			
			
			_planeRef.push( { face:_frontContainer, plane:_topicHolder } );
			
			
			_topicRoller = new Plane(rollmat, _toprollMC.width, _toprollMC.height, 3, 3);
			_topicRoller.z = -10;
			_topicRoller.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onTopicMenuClick);
			_topicRoller.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onTopicMenuRoll);
			_topicRoller.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onTopicMenuRoll);

			_topicHolder.addChild(_topicRoller, "topicRoller");
			
			_planeRef.push( { face:_topicHolder, plane:_topicRoller } );
			
			
			_topcloseMC = new ModTopicCloser();
			_mcref.push(_topcloseMC);
			
			var closemat:MovieMaterial = new MovieMaterial(_topcloseMC, true, false, false);
			_topcloseMC.defmat = closemat;
			closemat.smooth = true;
			closemat.doubleSided = false;
			closemat.interactive = true;
			
			_topicCloser = new Plane(closemat, _topcloseMC.width, _topcloseMC.height, 3, 3);
			_topicCloser.z = 10;
			_topicCloser.rotationZ  = 180;
			_topicCloser.rotationY = 180;
			_topicCloser.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onTopicCloseClick);
			_topicCloser.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onTopicMenuRoll);
			_topicCloser.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onTopicMenuRoll);	
			
			_topicHolder.addChild(_topicCloser, "topicCloser");
			_planeRef.push({face:_topicHolder, plane:_topicRoller});
			
			
		}
		private function createTopicLabel(animate:Boolean = false):void {
			try {
				_frontContainer.removeChild(_topicLabel);
			}catch (e:Error){
				
			}
			if (_modTop) {
				
				_modTop = null;
			}
			_modTop = new ModuleLabel();
			_modTop.definfo = { name:_defobj.steps[_currentTopic].audiourl.split("|").join(" ") };
			if (_mtopmat) {
				_mtopmat.destroy();
				_mtopmat = null;
			}
			_mtopmat = new MovieMaterial(_modTop, true, false, false);
			_mtopmat.smooth = true;
			_modTop.defmat = _mtopmat;
			
			
			_topicLabel = new Plane(_mtopmat, _modTop.width, _modTop.height, 3, 3);
			if(!animate){
				_topicLabel.z = -40;
			}else {
				_topicLabel.z = -1000;
				_topicLabel.rotationY = 180;
				TweenMax.to(_topicLabel, 1, { rotationY:0, z: -40, ease:Strong.easeInOut } );
			}
			_topicLabel.x = -48;
			_topicLabel.y = 145;
			_frontContainer.addChild(_topicLabel, "topicLabel");
			
		}
		private function onTopicCloseClick(evt:InteractiveScene3DEvent):void {
			try {
				contentLayer.animationResume();
			}catch (e:Error) {
				
			}
			_toprollMC.roll.visible = false;
			_toprollMC.defmat.drawBitmap();
			TweenMax.to(_modPauserHolder, .8, { rotationX:0, ease:Strong.easeInOut } );
			revertTopicButton();
		}
		private function revertTopicButton():void {
			_topcloseMC.roll.visible = false;
			_topcloseMC.defmat.drawBitmap();
			TweenMax.to(_topicHolder, .8, {rotationX:0, ease:Strong.easeInOut});
			pmenu.hideAll();
			deactivateControls();
			viewport.buttonMode = viewport.useHandCursor = false;
		}
		private function onTopicMenuRoll(evt:InteractiveScene3DEvent):void {
			if (evt.target == _topicRoller) {
				_toprollMC.roll.visible = (evt.type == InteractiveScene3DEvent.OBJECT_OVER);
				_toprollMC.defmat.drawBitmap();
			}else {
				_topcloseMC.roll.visible = (evt.type == InteractiveScene3DEvent.OBJECT_OVER);
				_topcloseMC.defmat.drawBitmap();
			}
			super.roll3DActions(evt);
		}
		private function onTopicMenuClick(evt:InteractiveScene3DEvent = null):void {
			try{
				contentLayer.animationPause();
			}catch(e:Error){
				
				
			}
			_toprollMC.roll.visible = false;
			_toprollMC.defmat.drawBitmap();
			TweenMax.to(_modPauserHolder, .8, { rotationX:180, ease:Strong.easeInOut } );
			TweenMax.to(_topicHolder, .8, {rotationX:180, ease:Strong.easeInOut});
			pmenu.showAll(_currentTopic);
			activateControls();
			pmenu.planes[_currentTopic].createInBetween(new CatNavItemRoll());
			
		}
		override protected function roll3DActions(evt:InteractiveScene3DEvent):void {
			
			var udata:Object = (evt.target as Plane).userData.data;
			
			var pmenuitem:PaperMenuItem  = udata.movie.pmenu;
			var rolled:Boolean = evt.type == InteractiveScene3DEvent.OBJECT_OVER;
			if (rolled) {
				pmenuitem.createInBetween(new CatNavItemRoll());
				TweenMax.to(pmenuitem, .6, { z: -60, ease:Strong.easeInOut} );	
			}else {
				pmenuitem.removeInBetween();
				TweenMax.to(pmenuitem, .6, {z:0, ease:Strong.easeInOut} );
			}			
			
			super.roll3DActions(evt);
		}
		private function resolveNewItem(newitem:PaperMenuItem):void{
			if(_lastSelected){
				_lastSelected.removeInBetween();
				TweenMax.to(_lastSelected, .6, {z:0, ease:Strong.easeInOut} );
				_lastSelected.deselect();
			}
			newitem.select();
			newitem.createInBetween(new CatNavItemRoll());
			TweenMax.to(newitem, .6, { z: -40, ease:Strong.easeInOut} );
			_lastSelected = newitem;	
			_currentTopic = newitem.defaultInformation.index;
			try {
				TweenMax.to(_nextClicker, 1, {ease:Strong.easeInOut, z:-1000, rotationY:-180, onComplete:_frontContainer.removeChild, onCompleteParams:[_nextClicker] } );
			}catch (e:Error) {
				
			}
			var toremove:Plane = _moduleTitle;
			TweenMax.to(toremove, 1, { ease:Strong.easeInOut, z: -1000, rotationY: -180, onComplete:_frontContainer.removeChild, onCompleteParams:[toremove] } );
			setTimeout(createModLabel, 300);
			
			
			setTimeout(revertTopicButton, 100);
			
			resolveResources();
			
			playAnimation();
		}
		override protected function click3DActions(evt:InteractiveScene3DEvent):void {
			var newitem:PaperMenuItem = evt.target.parent;
			try {
				if(_homeClicker){
					_frontContainer.removeChild(_homeClicker);
				}
			}catch (e:Error) {
				
			}
			dispatchEvent(new GenericEvent("ContentChanged", contentObject.steps[newitem.defaultInformation.index]));
			resolveNewItem(newitem);
		}
		public function changePlay(indx:Number):void{
			if(_currentTopic != indx){
				resolveNewItem(pmenu.planes[indx]);
			}
		}
		override public function remove(pobj:DisplayObject3D):void {
			
			//planeView.quickDestroyPreloader();
			contentLayer.clean();
			super.remove(pobj);
		}
		
	}
	
}